package away3d.core.partition ;


import away3d.core.base.SubMesh ;
import away3d.core.traverse.PartitionTraverser ;
import away3d.entities.Mesh ;



/**
 * MeshNode is a space partitioning leaf node that contains a Mesh object.
 */
class MeshNode extends EntityNode
{
    
    
    private var _mesh : Mesh ;
    
    
    
    /**
     * Creates a new MeshNode object.
     * @param mesh The mesh to be contained in the node.
     */
    public function MeshNode( mesh : Mesh )
    {
        
        super( mesh ) ;
        _mesh = mesh ;    // also keep a stronger typed reference
        
    }
    
    
    public function mesh( get_mesh, null ) : Mesh ;
    
    
    /**
     * The mesh object contained in the partition node.
     */
    private function get_mesh() : Mesh
    {
        
        return _mesh ;
        
    }
    
    
    /**
     * @inheritDoc
     */
    override public function acceptTraverser( traverser : PartitionTraverser )
    {
        
        super.acceptTraverser( traverser ) ;
        
        if( traverser.enterNode( this ) )
        {
            
            var subs    = _mesh.subMeshes ;
            var i       : Int  ;
            var len     = subs.length ;
            
            while ( i < len )
            {
                
                traverser.applyRenderable( subs[ i++ ] ) ;
                
            }
            
        }
        
        traverser.leaveNode( this ) ;
        
    }
    
    
}
}